<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul,li{
            list-style: none;
        }
        ul{
            display: flex;
            justify-content: space-evenly;
            padding: 10px 0;
        }
        ul li{
            border: 1px solid #ccc;
            width: 24%;
            display: flex;
            flex-direction: column;
            align-items: center;
            cursor: pointer;
            padding: 10px 0;
        }
        ul li img{
            width: 90%;
        }
        ul li p{
            width: 90%;
            margin: 5px;
        }
    </style>
</head>
<body>
    <ul id="goods">

    </ul>

    <script>
        var goodlist = [
            {id: 111, url: './images/g1.jpg', name: '美女1号', price: 1998, age: 20},
            {id: 22, url: './images/g2.jpg', name: '美女2号', price: 1998, age: 20},
            {id: 3456, url: './images/g3.jpg', name: '美女3号', price: 1998, age: 20},
            {id: 4458, url: './images/g4.jpg', name: '美女4号', price: 1998, age: 20},
            {id: 59877, url: './images/g1.jpg', name: '美女5号', price: 1998, age: 20}
        ]

        goodlist.forEach(function(item, index){
            goods.innerHTML += '<li idx= "' + item.id + '" class="goods1"><img src=" ' + item.url + '">' +
            '<p>姓名：' + item.name + '</p>' +
            '<p>价格：' + item.price + '</p>' +
            '<p>年龄：' + item.age + '</p>' +
            '</li>'
        })
        var list = document.getElementsByTagName('li');
        for(var i = 0; i < list.length; i++){
            list[i].onclick = function(){

                open('03.详情页.html?id=' + this.getAttribute('idx'));
            }  
        }
        //用数组形式，集合所有商品信息；
        //遍历数组，拼接信息，渲染到页面；
        //得到li元素，for循环，用open打开详情页面。
    </script>
    
</body>
</html>